package com.cjx.yuanshenstartforumbackend.controller;

import com.cjx.yuanshenstartforumbackend.common.BaseResponse;
import com.cjx.yuanshenstartforumbackend.common.ErrorCode;
import com.cjx.yuanshenstartforumbackend.domain.Article;
import com.cjx.yuanshenstartforumbackend.domain.dto.ArticleQueryDto;
import com.cjx.yuanshenstartforumbackend.domain.dto.InsertArticleDto;
import com.cjx.yuanshenstartforumbackend.domain.vo.ArticleCategoryVo;
import com.cjx.yuanshenstartforumbackend.exception.MyException;
import com.cjx.yuanshenstartforumbackend.service.ArticleCategoryService;
import com.cjx.yuanshenstartforumbackend.service.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description 文章类别Controller层
 * @Author cjx
 * @Date 2023/12/23 11:14
 **/

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    @PostMapping("/query")
    public BaseResponse<Map<String,Object>> queryPage(@RequestBody ArticleQueryDto articleQueryDto){
        return articleService.queryPage(articleQueryDto);
    }

    @GetMapping("/addReading")
    public BaseResponse<?> addReading(@RequestParam Long aid){
        if (aid == null){
            throw new MyException(ErrorCode.NULL_ERROR);
        }
        return articleService.addReading(aid);
    }

    @GetMapping("/getArticle")
    public BaseResponse<Article> getArticle(@RequestParam Long aid){
        if (aid == null){
            throw new MyException(ErrorCode.NULL_ERROR);
        }
        return articleService.getArticle(aid);
    }

    @PostMapping("/insertArticle")
    public BaseResponse<?> insertArticle(@RequestBody InsertArticleDto insertArticleDto){
        if (insertArticleDto == null){
            throw new MyException(ErrorCode.NULL_ERROR);
        }
        return articleService.insertArticle(insertArticleDto);
    }




}
